/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package technotheist.geo.map;

import com.jme3.scene.VertexBuffer;

/**
 *
 * @author Mitchel Strachan
 */
public enum Format {

    Int(VertexBuffer.Format.Int, Integer.MIN_VALUE, Integer.MAX_VALUE),
    UInt(VertexBuffer.Format.UnsignedInt, Integer.MIN_VALUE, Integer.MAX_VALUE, Int),
    Short(VertexBuffer.Format.Short, java.lang.Short.MIN_VALUE, java.lang.Short.MAX_VALUE),
    UShort(VertexBuffer.Format.Short, java.lang.Short.MIN_VALUE, java.lang.Short.MAX_VALUE, Short),
    Byte(VertexBuffer.Format.Byte, java.lang.Byte.MIN_VALUE, java.lang.Byte.MAX_VALUE),
    UByte(VertexBuffer.Format.Byte, java.lang.Byte.MIN_VALUE, java.lang.Byte.MAX_VALUE, Byte),
    Float(VertexBuffer.Format.Float, 0, 1);
    //
    //
    public final VertexBuffer.Format vbFormat;
    public final long min, max, span;
    public final int size;
    private Format signed;

    Format(VertexBuffer.Format vbFormat, long min, long max) {
        this(vbFormat, min, max, null);
    }

    Format(VertexBuffer.Format vbFormat, long min, long max, Format signed) {
        this.vbFormat = vbFormat;
        this.size = vbFormat.getComponentSize();
        this.min = min;
        this.max = max;
        this.span = max-min;
        this.signed = signed;
    }
    
    public long unsignedToSigned(long i) {
        if(signed == null) {
            return i;
        } else {
            return i + signed.min;
        }
    }
    public long signedToUnsigned(long i) {
        if(signed == null) {
            return i;
        } else {
            return i - signed.min;
        }
    }
    
    public boolean isUnsigned() {
        return signed != null;
    }
}
